package com.jd.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.jd.po.User;
import com.jd.service.GetProjectListService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class GetProjectListAction extends ActionSupport {
	private String areaId;
	private GetProjectListService getProjectListService;

	public GetProjectListService getGetProjectListService() {
		return getProjectListService;
	}

	public void setGetProjectListService(GetProjectListService getProjectListService) {
		this.getProjectListService = getProjectListService;
	}
	
	public void getFileList() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		HttpServletRequest request = ServletActionContext.getRequest();
		Map session = ActionContext.getContext().getSession();
		PrintWriter out=response.getWriter();
		String userGroup = ((User)session.get("user")).getUserGroup();
		if(areaId!=null&&areaId.trim().length()>0){
			String callback = request.getParameter("callback");
			List<String> areaList = getProjectListService.findProjectByGroup(userGroup, areaId);
			JSONArray jsonArray = JSONArray.fromObject(areaList);
			JSONObject jsobj = new JSONObject();
			jsobj.put("data", jsonArray);
			System.out.println(jsobj.toString());
			//out.append(jsobj.toString());
			out.print(jsonArray.toString());
			//out.write(jsobj.toString());
			//out.println();
			out.flush();
		}
	}


	public String execute() throws Exception {
		return SUCCESS;
		
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getAreaId() {
		return areaId;
	}

}
